//
//  NSBundle+AppIcon.m
//  iOS-Categories (https://github.com/shaojiankui/iOS-Categories)
//
//  Created by Jakey on 14/12/15.
//  Copyright (c) 2014年 www.skyfox.org. All rights reserved.
//

#import "NSBundle+AppIcon.h"
#import "JFStringHelper.h"

@implementation NSBundle (AppIcon)
- (NSString*)appIconPath {
    NSString* iconFilename = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIconFile"] ;
    NSString* iconBasename = [iconFilename stringByDeletingPathExtension] ;
    NSString* iconExtension = [iconFilename pathExtension] ;
    return [[NSBundle mainBundle] pathForResource:iconBasename
                                           ofType:iconExtension] ;
}

- (UIImage*)appIcon {
    UIImage*appIcon = [[UIImage alloc] initWithContentsOfFile:[self appIconPath]] ;
    return appIcon;
}

+ (NSBundle *)bundleWithName:(NSString*)bundleName {
    if ([JFStringHelper isNotEmpty:bundleName]) {
        NSString *resourceBundlePath = [[NSBundle mainBundle] pathForResource:bundleName ofType:@"bundle"];
        NSBundle *bundle = [NSBundle bundleWithPath:resourceBundlePath];
        if(!bundle){
           resourceBundlePath = [[NSBundle mainBundle] pathForResource:bundleName ofType:@"framework"];
           bundle =  [NSBundle bundleWithPath:resourceBundlePath];
        }
        return bundle;
    }else{
        return nil;
    }
}
+ (UIView *)loadViewWithXibName:(NSString *)name{
   return [self loadViewWithXibName:name buddleName:nil];
}
+ (UIView *)loadViewWithXibName:(NSString *)name buddleName:(NSString*)buddleName{
    NSBundle * bundle = [self bundleWithName:buddleName];
    if (!bundle) {
        bundle = [NSBundle mainBundle];
    }
    return [[bundle loadNibNamed:name owner:nil options:nil] firstObject];
}


@end
